import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    host: '0.0.0.0',
    port: 9000,
    open: true,
    proxy: {
      '/api': {
        target: 'https://www.fastmock.site/mock/24029b8aaced73da3b7eda33e8ac0202',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api'),
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@a': fileURLToPath(new URL('./src/api', import.meta.url)),
      '@c': fileURLToPath(new URL('./src/components', import.meta.url)),
      '@s': fileURLToPath(new URL('./src/store', import.meta.url)),
      '@u': fileURLToPath(new URL('./src/utils', import.meta.url)),
      '@p': fileURLToPath(new URL('./src/pages', import.meta.url))
    }
  }
})
